package io.cloud.tec.reactor;


import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

/**
 * gatling：https://gatling.io/docs/gatling/tutorials/quickstart/
 *
 * //     mvn gatling:test -Dgatling.simulationClass=test.load.sims.LoadSimulation -Dbase.url=http://localhost:8091/ -Dtest.path=hello/100 -Dsim.users=300
 */
public class LoadSimulation extends Simulation {
//    String baseUrl = System.getProperty("base.url");
//    String testPath = System.getProperty("test.path");
//    Integer sim_users = Integer.parseInt(System.getProperty("sim.users"));
    String baseUrl = "http://localhost:8082";
    String testPath = "/account";
    Integer sim_users = 300;

    HttpProtocolBuilder httpConf = http // 4
            .baseUrl(baseUrl) // 5
            .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // 6
            .doNotTrackHeader("1")
            .acceptLanguageHeader("en-US,en;q=0.5")
            .acceptEncodingHeader("gzip, deflate")
            .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0");

    // 定义模拟的请求，重复30次
    ChainBuilder helloRequest = repeat(1).on(ChainBuilder.EMPTY.exec(
            http("hello-with-latency").get(testPath)).pause(1, 2));

    ScenarioBuilder scn = scenario("BasicSimulation") // 7
            .exec(helloRequest);

    {
        setUp(scn.injectOpen(rampUsers(sim_users).during(30))).protocols(httpConf);
    }

}
